<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>GSAP的滚动插件</title>
    <style>
        body {
            height: 2000px;
        }

        .demo {
            width: 50px;
            height: 50px;
            background-color: aqua;
            margin-top: 200px;
        }
    </style>
</head>

<body>
    <div class="demo"></div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.8.0/gsap.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.8.0/ScrollTrigger.min.js"></script>
    <script>
        const img = document.querySelector('.demo')
        gsap.registerPlugin(ScrollTrigger)
        gsap.fromTo(img, { x: 0, rotate: 0 },
            {
                x(_, target) {
                    return document.documentElement.clientWidth - target.offsetWidth;
                }, rotate: 360, duration: 3, ease: 'none', scrollTrigger: {
                    trigger: img,
                    scrub: true,
                    pin: true,
                    start: 'center center'
                }
            });
    </script>
</body>

</html>